import functools

from flask import current_app

from flask import session




def user_login_data(func):

    @functools.wraps(func)
    def wrapper(*args,**kwargs):

        user_id = session.get('user_id')
        user = None
        if user_id:
            try:
                from info.models import User
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        from flask import g
        g.user = user

        return func(*args,**kwargs)

    return wrapper





def do_index_class(index):
    """自定义过滤器，过滤点击排序html的class"""
    if index == 0:
        return "first"
    elif index == 1:
        return "second"
    elif index == 2:
        return "third"
    else:
        return ""


